<%= GMap.header %> 

<script type="text/javascript">
	function create_draggable_editable_marker() {
		GEvent.addListener(map, "click", function(marker, point)  {
			if (marker) { 
				point = marker.getPoint();
			}
			else { // if the user clicks somewhere other than existing marker 
				new Ajax.Request('/geo_locations/add_new_marker?pointy=' + point.y + '&pointx=' +point.x, 
				{asynchronous:true, evalScripts:true});
			} 
		});	
	}  
</script>

<h1>Add a new Location</h1>

<%= error_messages_for :geo_location %>

<table width="100%">
	<tr>
		<td width="50%" valign="top">
			<div class="description">
				<label>
					To position a map type an address or a place name and click <b>Find</b>, then place a marker by clicking on the map and fill in the new location name and description.
				</label>
			</div>	
			<% form_remote_tag(:url => {:action => :find_location}) do %>
			<div id="find_location" >
				<%= text_field_tag "geo_code", "", :size => "45" %>
				<%= submit_tag "Find" %>
			</div>
			<% end %>
		</td>
		<td>
		</td>
	</tr>
	
	<%
	session[:return] = params[:return]
	%>
	
	<% form_for(:geo_location, :url => geo_locations_path) do |f| %>
	<tr>
		<td valign="top">
			<%= @map.div(:width => 400, :height => 280) %>							
			<%= @map.to_html %>
		</td>
		<td valign="top" class="description">
			<p>
			<%= f.hidden_field :lat, :value => "" %>
			<%= f.hidden_field :lng, :value => "" %>			
			<label>Name:</label>
			<%= f.text_field :name %> 
			<br/><label>Description:</label>
			<%= f.text_area :description, :rows => 15, :cols => 45 %>			
			</p>
			<%=submit_tag "Save new Location"%>
			<!-- <%= link_to 'back', user_stories_path(current_user)%> -->
		</td>
	</tr>
	<% end %>				
</table>